package com.yunwrite.playerlibrary.customplayer.player;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 播放器管理类,能改实现播放器的获取、销毁、调度
 * @author liuping
 */
public class CustomPlayerManager {
    private static List<CustomPlayer> playerList = new ArrayList<>( );
    /**
     * 获取当前闲置的播放器,有的话则取一个，没有的话，创建一个，放入播放器列表复用
     *
     * @return
     */
    public static CustomPlayer getCustomPlayer() {
        CustomPlayer customPlayer = null;
        for (CustomPlayer player : playerList) {
            if (CustomPlayer.FREE == player.getState( )) {
                customPlayer = CustomPlayer.getInitCustomPlayer();
            }
        }
        if (null == customPlayer) {
            customPlayer = CustomPlayer.getInitCustomPlayer();
            playerList.add(customPlayer);
        }
        return customPlayer;

    }
}
